package com.gc.widget;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class Utils {

	public static void write(InputStream is, File file) {
		try {
			FileOutputStream fos = new FileOutputStream(file);
			try {
				write(is,fos);
			} finally {
				fos.close();
			}
		} catch(IOException ioEx) {
			throw new RuntimeException(ioEx);
		}
	}
	
	public static void write(InputStream is, OutputStream os) throws IOException {
		byte[] buffer = new byte[1024];
		while(true) {
			int nb = is.read(buffer);
			if(nb < 0)
				break;
			os.write(buffer,0,nb);
		}
	}
	
}
